package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: SetmealController
 *
 * @AUTHOR: zhang
 * DATE: 2023/11/29
 * DESCRIPTION :
 */
@Slf4j
@Api(tags = "C端-套餐信息表现层接口") //@Api:用户描述类的相关信息
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {

    @Resource
    private SetmealService setmealService;

    @ApiOperation("根据分类id查询套餐列表")
    @GetMapping("/list")
    @Cacheable(value = "SETMEAL_CACHE",key = "#categoryId")
    public Result<List<Setmeal>> selectSetmealByCategoryId(Long categoryId) {
        log.info("【根据分类id查询套餐列表】分类id：{}",categoryId);
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
        List<Setmeal> setmealList = setmealService.selectSetmealByCategoryId(setmeal);
        return Result.success(setmealList);
    }

    @ApiOperation("根据套餐id查询套餐菜品")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> selectSetmealDishBySetmealId(@PathVariable Long id){
        log.info("【根据套餐id查询套餐菜品】套餐id:{}",id);
        List<DishItemVO> dishItemVOList = setmealService.selectSetmealDishBySetmealId(id);
        return Result.success(dishItemVOList);
    }
}
